{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "file = \"fengkong_result_20220317.csv\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>call_id</th>\n",
       "      <th>cargo_tag</th>\n",
       "      <th>reason</th>\n",
       "      <th>asr_detail</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1200_11112_4294967295_20220303095453</td>\n",
       "      <td>0.0</td>\n",
       "      <td>非违禁品货源</td>\n",
       "      <td>[{\"start_time\": 500, \"end_time\": 920, \"text\": ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1200_2660_4294967295_20220310032810</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词错误，是转文本转错了</td>\n",
       "      <td>[{\"start_time\": 260, \"end_time\": 2060, \"text\":...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1201_14484_4294967295_20220314143246</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词错误，是转文本转错了</td>\n",
       "      <td>[{\"start_time\": 180, \"end_time\": 500, \"text\": ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1201_3323_4294967295_20220311080259</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[{\"start_time\": 620, \"end_time\": 1420, \"text\":...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1201_8342_4294967295_20220311001202</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词正确，用户仅仅聊到</td>\n",
       "      <td>[{\"start_time\": 0, \"end_time\": 480, \"text\": \"你...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4430</th>\n",
       "      <td>C20220316140741AC10210508428986966</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词错误，是转文本转错了</td>\n",
       "      <td>[{\"start_time\": 180, \"end_time\": 640, \"text\": ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4431</th>\n",
       "      <td>C20220316162422AC10213586760110486</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词错误，是转文本转错了</td>\n",
       "      <td>[{\"start_time\": 0, \"end_time\": 640, \"text\": \"喂...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4432</th>\n",
       "      <td>C20220316163234AC10213466901549006</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词正确，用户仅仅聊到</td>\n",
       "      <td>[{\"start_time\": 2620, \"end_time\": 3080, \"text\"...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4433</th>\n",
       "      <td>C20220316171121AC10212959234182603</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[{\"start_time\": 0, \"end_time\": 220, \"text\": \"啊...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4434</th>\n",
       "      <td>C20220316174221AC10212185164335911</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>[{\"start_time\": 120, \"end_time\": 580, \"text\": ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4435 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   call_id  cargo_tag       reason  \\\n",
       "0     1200_11112_4294967295_20220303095453        0.0       非违禁品货源   \n",
       "1      1200_2660_4294967295_20220310032810        0.0  词错误，是转文本转错了   \n",
       "2     1201_14484_4294967295_20220314143246        0.0  词错误，是转文本转错了   \n",
       "3      1201_3323_4294967295_20220311080259        NaN          NaN   \n",
       "4      1201_8342_4294967295_20220311001202        0.0   词正确，用户仅仅聊到   \n",
       "...                                    ...        ...          ...   \n",
       "4430    C20220316140741AC10210508428986966        0.0  词错误，是转文本转错了   \n",
       "4431    C20220316162422AC10213586760110486        0.0  词错误，是转文本转错了   \n",
       "4432    C20220316163234AC10213466901549006        0.0   词正确，用户仅仅聊到   \n",
       "4433    C20220316171121AC10212959234182603        NaN          NaN   \n",
       "4434    C20220316174221AC10212185164335911        NaN          NaN   \n",
       "\n",
       "                                             asr_detail  \n",
       "0     [{\"start_time\": 500, \"end_time\": 920, \"text\": ...  \n",
       "1     [{\"start_time\": 260, \"end_time\": 2060, \"text\":...  \n",
       "2     [{\"start_time\": 180, \"end_time\": 500, \"text\": ...  \n",
       "3     [{\"start_time\": 620, \"end_time\": 1420, \"text\":...  \n",
       "4     [{\"start_time\": 0, \"end_time\": 480, \"text\": \"你...  \n",
       "...                                                 ...  \n",
       "4430  [{\"start_time\": 180, \"end_time\": 640, \"text\": ...  \n",
       "4431  [{\"start_time\": 0, \"end_time\": 640, \"text\": \"喂...  \n",
       "4432  [{\"start_time\": 2620, \"end_time\": 3080, \"text\"...  \n",
       "4433  [{\"start_time\": 0, \"end_time\": 220, \"text\": \"啊...  \n",
       "4434  [{\"start_time\": 120, \"end_time\": 580, \"text\": ...  \n",
       "\n",
       "[4435 rows x 4 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(file,sep=\"\u0001\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>call_id</th>\n",
       "      <th>cargo_tag</th>\n",
       "      <th>reason</th>\n",
       "      <th>asr_detail</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1200_11112_4294967295_20220303095453</td>\n",
       "      <td>0.0</td>\n",
       "      <td>非违禁品货源</td>\n",
       "      <td>[{\"start_time\": 500, \"end_time\": 920, \"text\": ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1200_2660_4294967295_20220310032810</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词错误，是转文本转错了</td>\n",
       "      <td>[{\"start_time\": 260, \"end_time\": 2060, \"text\":...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1201_14484_4294967295_20220314143246</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词错误，是转文本转错了</td>\n",
       "      <td>[{\"start_time\": 180, \"end_time\": 500, \"text\": ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1201_8342_4294967295_20220311001202</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词正确，用户仅仅聊到</td>\n",
       "      <td>[{\"start_time\": 0, \"end_time\": 480, \"text\": \"你...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1202_14166_4294967295_20220304022255</td>\n",
       "      <td>0.0</td>\n",
       "      <td>非违禁品货源</td>\n",
       "      <td>[{\"start_time\": 320, \"end_time\": 760, \"text\": ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4428</th>\n",
       "      <td>C20220315151825AC10212775404275006</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词错误，是转文本转错了</td>\n",
       "      <td>[{\"start_time\": 160, \"end_time\": 1580, \"text\":...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4429</th>\n",
       "      <td>C20220316091656AC10213632741361963</td>\n",
       "      <td>1.0</td>\n",
       "      <td>近期承运违规货源信息（钢板下脚料）+运单号/货源id32466297309756，违反平台发货规则</td>\n",
       "      <td>[{\"start_time\": 0, \"end_time\": 7200, \"text\": \"...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4430</th>\n",
       "      <td>C20220316140741AC10210508428986966</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词错误，是转文本转错了</td>\n",
       "      <td>[{\"start_time\": 180, \"end_time\": 640, \"text\": ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4431</th>\n",
       "      <td>C20220316162422AC10213586760110486</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词错误，是转文本转错了</td>\n",
       "      <td>[{\"start_time\": 0, \"end_time\": 640, \"text\": \"喂...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4432</th>\n",
       "      <td>C20220316163234AC10213466901549006</td>\n",
       "      <td>0.0</td>\n",
       "      <td>词正确，用户仅仅聊到</td>\n",
       "      <td>[{\"start_time\": 2620, \"end_time\": 3080, \"text\"...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4062 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   call_id  cargo_tag  \\\n",
       "0     1200_11112_4294967295_20220303095453        0.0   \n",
       "1      1200_2660_4294967295_20220310032810        0.0   \n",
       "2     1201_14484_4294967295_20220314143246        0.0   \n",
       "4      1201_8342_4294967295_20220311001202        0.0   \n",
       "5     1202_14166_4294967295_20220304022255        0.0   \n",
       "...                                    ...        ...   \n",
       "4428    C20220315151825AC10212775404275006        0.0   \n",
       "4429    C20220316091656AC10213632741361963        1.0   \n",
       "4430    C20220316140741AC10210508428986966        0.0   \n",
       "4431    C20220316162422AC10213586760110486        0.0   \n",
       "4432    C20220316163234AC10213466901549006        0.0   \n",
       "\n",
       "                                                 reason  \\\n",
       "0                                                非违禁品货源   \n",
       "1                                           词错误，是转文本转错了   \n",
       "2                                           词错误，是转文本转错了   \n",
       "4                                            词正确，用户仅仅聊到   \n",
       "5                                                非违禁品货源   \n",
       "...                                                 ...   \n",
       "4428                                        词错误，是转文本转错了   \n",
       "4429  近期承运违规货源信息（钢板下脚料）+运单号/货源id32466297309756，违反平台发货规则   \n",
       "4430                                        词错误，是转文本转错了   \n",
       "4431                                        词错误，是转文本转错了   \n",
       "4432                                         词正确，用户仅仅聊到   \n",
       "\n",
       "                                             asr_detail  \n",
       "0     [{\"start_time\": 500, \"end_time\": 920, \"text\": ...  \n",
       "1     [{\"start_time\": 260, \"end_time\": 2060, \"text\":...  \n",
       "2     [{\"start_time\": 180, \"end_time\": 500, \"text\": ...  \n",
       "4     [{\"start_time\": 0, \"end_time\": 480, \"text\": \"你...  \n",
       "5     [{\"start_time\": 320, \"end_time\": 760, \"text\": ...  \n",
       "...                                                 ...  \n",
       "4428  [{\"start_time\": 160, \"end_time\": 1580, \"text\":...  \n",
       "4429  [{\"start_time\": 0, \"end_time\": 7200, \"text\": \"...  \n",
       "4430  [{\"start_time\": 180, \"end_time\": 640, \"text\": ...  \n",
       "4431  [{\"start_time\": 0, \"end_time\": 640, \"text\": \"喂...  \n",
       "4432  [{\"start_time\": 2620, \"end_time\": 3080, \"text\"...  \n",
       "\n",
       "[4062 rows x 4 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dropna(inplace=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "import time\n",
    "def process_data(item):\n",
    "    json_obj = json.loads(item['asr_detail'])\n",
    "    result = []\n",
    "    for i in json_obj:\n",
    "        result.append(i['role'] + \":\" + i[\"text\"])\n",
    "    return result\n",
    "\n",
    "def post_server(data):\n",
    "    url = 'http://predict-phantom.amh-group.com/contraband/v1/models/contraband:predict'\n",
    "    header = {\n",
    "        'Content-Type':\"application/json\"\n",
    "    }\n",
    "    post_data = {\n",
    "        'dialogue':[data],\n",
    "        \"predict_detail\":1\n",
    "        \n",
    "    }\n",
    "\n",
    "    req = requests.post(url,data=json.dumps(post_data),headers=header)\n",
    "    time.sleep(0.05)\n",
    "    return req.json()\n",
    "\n",
    "def make_predict_data(item):\n",
    "    output = []\n",
    "    dialog_dict = item[\"asr_detail\"]\n",
    "    dialog_list = process_data(dialog_dict)\n",
    "    result = post_server(dialog_list)\n",
    "    if \"contraband_infos\" in result:\n",
    "        if \"origin_dialogue\" in result[\"contraband_infos\"][\"\"]:\n",
    "            for i in result[\"contraband_infos\"][\"origin_dialogue\"]:\n",
    "                if i[1] == \"是\"：\n",
    "                output.append(i[0])\n",
    "    return result\n",
    "            "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}